<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
<script>

  const onlineMembers = new Map([["40001", {}]])


  function breakDataSource(item) {
    if (item.personId) {
      item.title = item.accountName || "默认name";
      item.userId = item.account;
      item.treeId = item.id;
    } else if(item.orgId || item.orgName) {
      item.title = item.orgName;
      item.id = item.orgId;
      item.treeId = item.orgId;
    } else if (item.deptId || item.deptName) {
      item.title = item.deptName;
      item.id = item.deptId;
      item.treeId = item.deptId;
    }

    item.type = '1' // 叶子节点标识

    if (item.values) {
      item.children = item.values.map(breakDataSource);
      item.type = '0'
    }

    if (item.child) {
      item.children = item.child.map(breakDataSource);
      item.type = '0'
    }

    return item
  }

  function filterUsersOnline(users) {
    const __users = []
    users.forEach(item => {
      if (item.children) {
        item.children = this.filterUsersOnline(item.children)
        if (item.children.length) {
          __users.push(item)
        }
      } else {
        const online = onlineMembers.has(item.userId)
        if (online) {
          item.disabled = false
          __users.push(item)
        }
      }
    })

    return __users
  }

  fetch(`http://192.168.1.100:27003/classroom/selectAllStructure?accountName=`, {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': '7b8a6e42ad2fad5e8d78427e54b78707',
    },
    body: "{}",
  }).then(res => res.json()).then(({ result, success }) => {
    console.log(result, success)
    if (success === true) {
      const dataSource = result.map(breakDataSource)

      console.log(dataSource, filterUsersOnline(dataSource))
    }
  })
</script>
</body>
</html>